package com.lc202407;

import java.util.HashMap;

public class Solution387 {
    public int firstUniqChar(String s) {
        int length = s.length();
        HashMap<Character, Integer> count = new HashMap<>();
        for (int i = 0; i < length; i++) {
            char key = s.charAt(i);
            int num = count.getOrDefault(key, 0) + 1;
            count.put(key, num);
        }
        for (int i = 0; i < length; i++) {
            if (count.get(s.charAt(i)) == 1) {
                return i;
            }
        }
        return -1;
    }
}
